package com.ruoyi.schoolSys.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.schoolSys.mapper.TeachMapper;
import com.ruoyi.schoolSys.service.TeachService;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.ruoyi.schoolSys.cache.CacheUtil.cacheTeacherList;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2024</p>
 * <p>公司: 中科天巡</p>
 *
 * @version: 1.0
 * @author: WangChaoTao
 * @date 2024/2/14
 */
@Service
public class TeachServiceImpl implements TeachService {

    @Autowired
    private TeachMapper teachMapper;
    @Autowired
    private SysUserMapper sysUserMapper;


    /**
     * 获取所有角色为老师的用户
     * @return
     */
    @Override
    public List<SysUser> getAllTeacher() {

        List<SysUser> teacherList = new ArrayList<>();
        List<Long> teacherIdList = teachMapper.getTeacherId();
        teacherIdList.forEach(teacherId -> {
            SysUser sysUser = sysUserMapper.selectUserById(teacherId);
            teacherList.add(sysUser);
            cacheTeacherList.add(sysUser);
        });

        return teacherList;

    }

    /**
     * 获取所有角色为家长的用户
     * @return
     */
    @Override
    public List<SysUser> getAllPatriarch() {

        List<SysUser> patriarchList = teachMapper.getAllPatriarchList();


        return patriarchList;
    }
}